<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>添加疫苗种类信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户编号</label>
            <div class="layui-input-block">
                <input type="number" name="user_id" lay-verify="required" lay-reqtext="用户编号不能为空" placeholder="请输入用户编号"
                    value="" class="layui-input">
            </div>
        </div>


        <!-- <div class="layui-form-item">
            <label class="layui-form-label required">评论内容</label>
            <div class="layui-input-block">
                <input type="text" name="comments_content" lay-verify="required" lay-reqtext="内容不能为空"
                    placeholder="请输入内容" value="" class="layui-input">
            </div>
        </div> -->

        <!-- <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">评论内容</label>
            <div class="layui-input-block">
                <textarea name="comments_content" class="layui-textarea" lay-reqtext="内容不能为空"
                    placeholder="请输入内容"></textarea>
            </div>
        </div> -->


        <!-- <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">评论内容</label>
            <div class="layui-input-block">
                <textarea name="news_content" class="layui-textarea" placeholder="请输入内容"></textarea>
                <textarea class="layui-textarea" name="comments_content" id="lay_content" style="display: none" placeholder="请输入评论内容">
                </textarea>
            </div>
        </div> -->





        <div class="layui-form-item">
            <label class="layui-form-label required">新闻编号</label>
            <div class="layui-input-block">
                <input type="number" name="news_id" lay-verify="required" lay-reqtext="新闻编号不能为空" placeholder="请输入新闻编号"
                    value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">评论内容(先保存再提交)</label>
            <div class="layui-input-block">
                <!-- <textarea name="comments_content" class="layui-textarea" placeholder="请输入新闻具体内容"></textarea> -->
                <input type="hidden" name="comments_content" id="comments_content">
                <textarea class="layui-textarea" id="lay_content" style="display: none" placeholder="请输入评论内容" ></textarea>
                <button class="layui-btn site-demo-layedit" data-type="content">保存内容</button>
            </div>
        </div>



        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"> 确 认  保 存  </button>
            </div>
        </div>
    </div>
    <script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layedit'], function () {
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                layedit = layui.layedit,
                $ = layui.$;


            laydate.render({
                elem: '#date'
            });


            //构建一个默认的编辑器
            var index = layedit.build('lay_content');
            //编辑器外部操作
            var active = {
                content: function () {
                     alert("保存成功"); //获取编辑器内容
                    $("#comments_content").val(layedit.getContent(index))
                }
            };

            $('.site-demo-layedit').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


            //监听提交
            form.on('submit(saveBtn)', function (data) {

                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {

                    $.ajax({
                        url: "http://localhost:8080/admin/news/comments/add",
                        data: data.field,
                        type: 'post',
                        success: function (result) {
                            if (result.code == 200) {
                                parent.layer.msg(result.message)
                                // 关闭弹出层
                                layer.close(index);
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            }
                        },
                        error: function (data) {
                            console.log("bbb = " + data)
                            layer.alert("添加失败!")
                        }
                    });

                });

                return false;
            });

        });
    </script>
</body>

</html>